//index.js
//获取应用实例
const app = getApp();
// var template = require('../header/header.js');

Page({
    data: {
        page: 1,
        pageSize: 10,
        list: [],
    },
    onLoad: function () {
        this.getList();
    },
    onHide: function () {

    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.data.page = 1;
        this.getList();
    },

    getList: function() {
        var _this = this;
        var object = {
            url: app.api.url.message.messageList,
            data: {page: _this.data.page, pageSize: _this.data.pageSize},
            success: function(res){
                if(res.status == 1) {
                    var list = res.data;
                    for(var i=0; i < list.length; i++) {
                        list[i]['createtime'] = app.util.dateTime(list[i]['createtime'], 'Y/m/d H:i');
                    }
                    _this.setData({
                        list: list
                    });
                } else {
                    app.showToast(res.info);
                }
            },
            complete: function() {
                wx.stopPullDownRefresh() //停止下拉刷新
            }
        }
        app.request(object);
    },

    onRead: function(e) {
        var _this = this;
        var id = e.currentTarget.dataset.id;
        var object = {
            url: app.api.url.message.messageDetail,
            data: {id: id},
            success: function(res){
                if(res.status == 1) {
                    _this.onPullDownRefresh();
                    app.showModal(res.data.title, res.data.content, false)
                } else {
                    app.showToast(res.info);
                }
            },
        }
        app.request(object);
    }
});
